begintownscript;

variables;
short bmessage,pcs,seated,leadchar,rctx,rcty;
string custom_m;

body;

beginstate INIT_STATE;

	turn_off_training(1);
	activate_hidden_group(8);
	set_terrain(23,27,270);
	set_terrain(45,24,270);
	set_terrain(39,40,270);
	set_terrain(35,55,270);
	set_terrain(52,52,270);
	set_terrain(51,34,270);
	set_terrain(46,15,270);
	set_terrain(49,12,270);
	set_terrain(53,13,270);
	set_terrain(53,19,270);
	set_terrain(59,18,270);
	set_terrain(59,13,270);
	force_instant_terrain_redraw();
	pause(6);
	reset_dialog();
	add_dialog_str(0,"By the time you reach Pleasantville, it's nighttime.  The doors are all closed, likely because of the bandits, and a soldier approaches you.  He appears glad to see you.",0);
	add_dialog_str(1,"_Ah!  You.  Quickly.  Come with me to city hall._",0);
	add_dialog_str(2,"He quickly shuffles down the road, not wanting to be in the cold for too long.",0);
	add_dialog_choice(0,". . .");
	bmessage = run_dialog(0);
	change_blocked(52,47,1);
	change_blocked(47,25,1);
	change_blocked(46,25,1);
	erase_char(24);
	force_instant_terrain_redraw();

break;

beginstate EXIT_STATE;
break;

beginstate START_STATE;

	if(get_flag(1,0) < 9){
		set_char_status(6,4,2,1,0);
		set_char_status(7,4,2,1,0);
		set_char_status(8,4,2,1,0);
		set_attitude(6,3);
		set_attitude(7,3);
		set_attitude(8,3);
	}

	if(get_flag(1,0) < 11){
		pcs = 0;
		seated = 0;
		while((pcs <= 3) && (seated == 0)){
			if(char_ok(pcs) == TRUE){
				if((char_loc_x(pcs) <= 39) && (char_loc_y(pcs) >= 48)){
					message_dialog("Rocks don't move...  nor do they have fangs.","CRAP!  These spiders can camouflage themselves!  This'll be dangerous.");
					set_terrain(35,51,0);
					set_terrain(37,49,0);
					set_terrain(41,47,0);
					set_terrain(41,49,0);
					set_terrain(35,51,0);
					set_terrain(44,46,0);
					activate_hidden_group(2);
					force_instant_terrain_redraw();
					pause(2);
					seated = 1;
					set_flag(1,0,11);
				}
			}

			pcs = (pcs + 1);
		}
	}

break;

beginstate 10;

	message_dialog("You could theoretically leave, but that the mayor is waiting for you...  you are compelled to stay.","");
	block_entry(1);

break;

beginstate 11;

	if(get_flag(1,0) < 6){
		message_dialog("The mayor smiles.  _Finally, some assistance.  If you don't mind, I'd prefer to meet in the larger hall here.  I've already opened the door._","");
		set_flag(1,0,6);
	}

break;

beginstate 12;

	if(get_flag(1,0) >= 9)
		end();
	if(is_combat() == TRUE){
		block_entry(1);
		end();
	}

	march_party(32,38);
	force_view_center(32,38);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(49);

	march_party(33,37);
	force_view_center(33,37);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(50);

	march_party(33,36);
	force_view_center(33,36);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(49);

	march_party(33,35);
	force_view_center(33,35);
	set_character_facing(8,0);
	set_character_facing(7,0);
	set_character_facing(6,0);
	relocate_character(8,32,39);
	relocate_character(6,33,40);
	relocate_character(7,33,41);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(50);

	march_party(34,34);
	force_view_center(34,34);
	relocate_character(8,32,38);
	relocate_character(6,32,39);
	relocate_character(7,33,40);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(49);

	march_party(34,33);
	force_view_center(34,33);
	relocate_character(8,31,37);
	relocate_character(6,32,38);
	relocate_character(7,32,39);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(50);

	march_party(34,32);
	force_view_center(34,32);
	relocate_character(8,30,36);
	relocate_character(6,32,37);
	relocate_character(7,32,38);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(49);

	march_party(35,31);
	force_view_center(35,31);
	relocate_character(8,30,35);
	relocate_character(6,32,36);
	relocate_character(7,33,37);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(50);

	march_party(35,30);
	force_view_center(35,30);
	relocate_character(6,32,35);
	relocate_character(7,34,36);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(49);

	march_party(34,29);
	force_view_center(34,29);
	relocate_character(6,32,34);
	relocate_character(7,34,35);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(50);

	march_party(33,29);
	force_view_center(33,29);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(49);

	march_party(32,29);
	force_view_center(32,29);
	force_instant_terrain_redraw();
	pause(4);
	play_sound(50);

	if(party_size() > 1){
		march_party(31,29);
		force_view_center(31,29);
		force_instant_terrain_redraw();
		pause(4);
		play_sound(49);
	}

	if(party_size() > 3){
		march_party(30,29);
		force_view_center(30,29);
		force_instant_terrain_redraw();
		pause(4);
		play_sound(50);
	}
	set_character_facing(1000,4);
	force_instant_terrain_redraw();
	pause(2);

	reset_dialog();
	add_dialog_str(0,"The mayor begins to speak, but something odd happens.",0);
	add_dialog_str(1,"_Market dog blue road.  Colorless green ideas sleep furiously.  Upheave ill person making in far away._",0);
	add_dialog_str(2,"What the hell is this?  Some sort of bad joke?",0);
	add_dialog_choice(0,"Um...  what're you saying?");
	bmessage = run_dialog(1);

	move_item_on_spot(30,33,-1,-1);
	move_item_on_spot(33,32,-1,-1);
	set_terrain(30,33,223);
	set_terrain(33,32,224);
	force_instant_terrain_redraw();
	pause(1);

	reset_dialog();
	add_dialog_str(0,"Wait a second...  Pleasantville was never this large, was it?",0);
	add_dialog_choice(0,". . .");
	bmessage = run_dialog(0);

	set_terrain(36,38,209);
	set_terrain(28,38,209);
	set_terrain(36,31,209);
	set_terrain(28,31,209);
	force_instant_terrain_redraw();
	pause(1);

	reset_dialog();
	add_dialog_str(0,"And there were never any reports of bandits in the area before...",0);
	add_dialog_choice(0,". . .");
	bmessage = run_dialog(0);

	set_terrain(29,32,133);
	set_terrain(35,32,133);
	set_terrain(29,38,0);
	set_terrain(35,38,0);
	force_instant_terrain_redraw();
	pause(1);

	reset_dialog();
	add_dialog_str(0,"But then, that doesn't explain why you're here...",0);
	add_dialog_choice(0,". . .");
	bmessage = run_dialog(0);

	set_terrain(32,34,0);
	set_terrain(32,36,0);
	set_terrain(32,38,0);
	set_terrain(29,34,0);
	set_terrain(29,35,0);
	set_terrain(29,36,0);
	set_terrain(35,34,0);
	set_terrain(35,35,0);
	set_terrain(35,36,0);
	force_instant_terrain_redraw();
	pause(1);

	reset_dialog();
	add_dialog_str(0,"There's something wrong with this picture.",0);
	add_dialog_choice(0,". . .");
	bmessage = run_dialog(0);

	set_terrain(30,30,0);
	set_terrain(31,30,0);
	set_terrain(32,30,0);
	set_terrain(33,30,0);
	set_terrain(34,30,0);
	set_terrain(29,29,216);
	set_terrain(35,29,216);
	force_instant_terrain_redraw();
	pause(2);

	set_terrain(32,33,277);
	set_terrain(28,30,0);
	set_terrain(28,33,0);
	set_terrain(28,36,0);
	erase_char(6);
	erase_char(7);
	erase_char(8);
	activate_hidden_group(1);
	force_instant_terrain_redraw();
	pause(3);

	reset_dialog();
	add_dialog_str(0,"...you must have gotten lost somewhere while you were daydreaming.  But now, you are absolutely certain that three pests lie in front of you.",0);
	add_dialog_str(1,"Still, you aren't afraid.  You aren't.  You were simply caught off-guard by a little extra courage.",0);
	add_dialog_choice(0,". . .");
	bmessage = run_dialog(1);

	set_flag(1,0,9);
	block_entry(1);

break;

beginstate 13;

	if(((char_ok(9) == TRUE) || (char_ok(10) == TRUE)) || (char_ok(11) == TRUE)){
		message_dialog("Slay the spiders first, then worry about escaping.","");
		block_entry(1);
		end();
	}
	if(get_flag(1,0) == 9){
		rctx = 28;
		while(rctx <= 36){
			rcty = 28;
			while(rcty <= 38){
				set_floor(rctx,rcty,0);
				if(get_ran(1,0,4) == 0)
					set_floor(rctx,rcty,get_ran(1,1,3));

				rcty = (rcty + 1);
			}
			rctx = (rctx + 1);
		}
		rcty = 28;
		while(rcty <= 37){
			set_terrain(27,rcty,5);
			if(rcty <= 34)
				set_terrain(37,rcty,3);

			rcty = (rcty + 1);
		}
		rctx = 27;
		while(rctx <= 34){
			rcty = 39;
			while(rcty <= 44){
				set_terrain(rctx,rcty,0);
				set_floor(rctx,rcty,255);

				rcty = (rcty + 1);
			}
			rctx = (rctx + 1);
		}
		rctx = 28;
		while(rctx <= 35){
			set_terrain(rctx,28,0);

			rctx = (rctx + 1);
		}
		set_terrain(36,28,7);
		set_floor(36,28,255);
		set_terrain(37,35,7);
		set_terrain(27,38,0);
		set_terrain(28,38,2);
		set_floor(28,38,255);
		set_terrain(29,38,9);
		set_floor(29,38,255);
		set_terrain(28,39,0);
		set_terrain(29,39,0);
		set_terrain(30,39,2);
		set_terrain(31,39,2);
		set_terrain(32,39,2);
		set_terrain(33,39,2);
		set_terrain(34,39,9);
		set_terrain(35,39,0);
		set_terrain(36,39,166);
		set_terrain(37,38,0);
		set_terrain(37,37,0);
		set_terrain(37,36,166);
		set_terrain(37,35,7);
		force_instant_terrain_redraw();
		pause(6);

		reset_dialog();
		add_dialog_str(0,"Wow!  You were really oblivious as you were fighting.  This isn't actually a wooden floor; it's a cave!  Silly you.",0);
		add_dialog_str(1,"But that means that you've forgotten your sense of direction...  now, you have to figure out whence you came.  You need to stay more focussed!  But hey, you're still okay.",0);
		add_dialog_choice(0,". . .");
		bmessage = run_dialog(1);

		set_flag(1,0,10);
		block_entry(1);
	}

break;

beginstate 14;

	if(get_flag(2,0) == 0){
		message_dialog("A bunch of people got lost here.  Fortunately, they weren't stripped of their possessions.","");
		set_flag(2,0,1);
	}

break;

beginstate 15;

	if(get_flag(1,0) < 12){
		if(is_combat() == TRUE){
			block_entry(1);
			end();
		}
		rctx = 30;
		while(rctx <= 40){
			rcty = 60;
			while(rcty <= 63){
				set_floor(rctx,rcty,255);
				set_terrain(rctx,rcty,0);
				rcty = (rcty + 1);
			}
			rctx = (rctx + 1);
		}
		set_terrain(33,56,9);
		set_terrain(33,57,5);
		set_terrain(33,58,0);
		set_terrain(34,58,9);
		set_floor(33,56,255);
		set_floor(33,57,255);
		set_floor(33,58,255);
		set_floor(34,58,255);
		rctx = 33;
		while(rctx <= 38){
			set_terrain(rctx,59,2);
			set_floor(rctx,59,255);
			rctx = (rctx + 1);
		}
		set_terrain(31,59,0);
		set_floor(32,59,255);
		set_terrain(39,56,166);
		set_terrain(39,57,0);
		set_terrain(39,58,0);
		set_terrain(34,59,0);
		set_terrain(33,59,0);
		set_terrain(32,58,0);
		set_terrain(32,57,0);
		set_terrain(32,56,0);
		set_terrain(39,59,2);
		force_instant_terrain_redraw();
		pause(4);
		message_dialog("What the...","You have to stop daydreaming.  This isn't an exit.  Concentrate!  What if you were to make a mistake like this with those dangerous spiders trying to get you?");
		set_flag(1,0,12);
		block_entry(1);
	}

break;

beginstate 16;

	if(get_flag(1,0) < 13){
		rctx = 48;
		while(rctx <= 55){
			rcty = 36;
			while(rcty <= 43){
				set_floor(rctx,rcty,255);
				set_terrain(rctx,rcty,0);
				set_height(rctx,rcty,7);
				rcty = (rcty + 1);
			}
			rctx = (rctx + 1);
		}
		rctx = 51;
		while(rctx <= 53){
			rcty = 44;
			while(rcty <= 47){
				set_terrain(52,rcty,0);
				set_height(rctx,rcty,7);
				rcty = (rcty + 1);
			}
			rctx = (rctx + 1);
		}
		set_terrain(51,36,9);
		set_floor(52,36,0);
		set_terrain(53,36,3);
		rcty = 37;
		while(rcty <= 43){
			set_terrain(51,rcty,5);
			set_floor(52,rcty,0);
			set_terrain(53,rcty,3);
			rcty = (rcty + 1);
		}
		set_floor(52,38,1);
		set_floor(52,39,2);
		set_floor(52,41,1);
		set_floor(52,42,3);
		set_terrain(52,40,166);
		set_terrain(52,45,270);
		activate_hidden_group(3);
		force_instant_terrain_redraw();
		pause(5);

		reset_dialog();
		add_dialog_str(0,"This is wrong.  Something is wrong.  You should not be here.  That should not be the exit of the cave.  You should be in Pleasantville-- how did you get lost?",0);
		add_dialog_str(1,"There are spiders here.  You didn't hear them coming.  You should have.  Were you daydreaming again?  This is all a bit...  worrisome.",0);
		add_dialog_str(2,"But buck up-- you've got nothing to be afraid of!  Right?",0);
		add_dialog_choice(0,". . .");
		bmessage = run_dialog(1);

		change_blocked(52,47,0);
		set_flag(1,0,13);
		block_entry(1);
	}

break;

beginstate 17;

	if(get_flag(3,0) == 0){
		message_dialog("There are runes placed here that glow gently, lighting up the caves.  This is most likely the work of a passing, benevolent mage who didn't want people to get trapped here.","");
		set_flag(3,0,1);
	}

break;

beginstate 18;

	if(is_combat() == TRUE){
		block_entry(1);
		end();
	}
	march_party(48,25);
	force_view_center(48,25);
	force_instant_terrain_redraw();
	play_sound(49);
	pause(4);

	march_party(49,24);
	force_view_center(49,24);
	force_instant_terrain_redraw();
	play_sound(50);
	pause(4);

	march_party(49,23);
	force_view_center(49,23);
	force_instant_terrain_redraw();
	play_sound(49);
	pause(4);

	march_party(49,22);
	force_view_center(49,22);
	force_instant_terrain_redraw();
	play_sound(50);
	pause(4);

	march_party(50,21);
	force_view_center(50,21);
	force_instant_terrain_redraw();
	play_sound(49);
	pause(4);

	set_character_facing(1000,6);
	force_instant_terrain_redraw();
	play_sound(50);
	pause(4);

	reset_dialog();
	add_dialog_str(0,"This network of caves seems more...  expansive than you remember any in the area being.",0);
	add_dialog_str(1,"...speaking of which, rubble shouldn't crumple underneath your feet.",0);
	add_dialog_choice(0,". . .");
	bmessage = run_dialog(1);
	pause(2);

	set_terrain(47,13,492);
	set_terrain(49,14,492);
	set_terrain(47,15,492);
	set_terrain(44,19,492);
	set_terrain(45,23,492);
	set_terrain(51,20,492);
	force_instant_terrain_redraw();
	pause(1);

	set_terrain(48,13,492);
	set_terrain(49,13,492);
	set_terrain(48,15,492);
	set_terrain(52,12,492);
	set_terrain(51,16,492);
	set_terrain(47,19,492);
	force_instant_terrain_redraw();
	pause(1);

	set_terrain(47,14,492);
	set_terrain(45,22,492);
	set_terrain(51,16,492);
	set_terrain(53,18,492);
	set_terrain(47,19,492);
	set_terrain(50,20,492);
	force_instant_terrain_redraw();
	pause(1);

	set_terrain(49,21,492);
	set_terrain(48,24,492);
	set_terrain(47,27,492);
	set_terrain(45,23,492);
	set_terrain(52,15,492);
	set_terrain(44,21,492);
	force_instant_terrain_redraw();
	pause(1);

	reset_dialog();
	add_dialog_str(0,"Insect casings, however, should most definitely crack underneath your feet.",0);
	add_dialog_str(1,"By the way, was there ever such a place as Pleasantville?",0);
	add_dialog_choice(0,". . . ?");
	bmessage = run_dialog(1);

	set_terrain(53,14,0);
	set_terrain(47,17,0);
	set_terrain(47,21,0);
	set_terrain(44,23,0);
	set_terrain(49,25,0);
	activate_hidden_group(4);
	relocate_character(25,53,14);
	relocate_character(26,47,21);
	relocate_character(27,49,25);
	relocate_character(28,44,23);
	relocate_character(29,47,17);
	force_instant_terrain_redraw();
	pause(2);

	reset_dialog();
	add_dialog_str(0,"You don't ever recall being there, or seeing it on any maps...  but weren't you there just a second ago?  It's hard to remember.",0);
	add_dialog_str(1,"Ah, but Peacechild was warning you not to leave his hut after drinking that potion...  he was screaming and begging, but you were so stubborn!",0);
	add_dialog_str(2,"Wait...  why were you seeing Peacechild?",0);
	add_dialog_choice(0,". . .");
	bmessage = run_dialog(1);

	set_terrain(43,19,0);
	set_terrain(44,20,0);
	set_terrain(51,19,0);
	set_terrain(53,21,0);
	activate_hidden_group(5);
	relocate_character(30,43,19);
	relocate_character(31,51,19);
	relocate_character(32,53,21);
	relocate_character(33,44,20);
	force_instant_terrain_redraw();
	pause(2);

	reset_dialog();
	add_dialog_str(0,"Oh...  that's right...",0);
	add_dialog_str(1,"This frontier was never known for its bandits-- it was known for its huge spider nest that extended for miles.",0);
	add_dialog_str(2,"You wanted to get a potion from Peacechild to help cure your arachnaphobia.",0);
	add_dialog_choice(0,". . .");
	bmessage = run_dialog(1);

	set_terrain(47,20,0);
	set_terrain(46,18,0);
	set_terrain(60,18,0);
	set_terrain(51,15,0);
	set_terrain(52,13,0);
	set_terrain(48,14,0);
	activate_hidden_group(6);
	relocate_character(34,51,15);
	relocate_character(35,47,29);
	relocate_character(36,46,18);
	relocate_character(37,50,18);
	relocate_character(38,52,13);
	relocate_character(39,48,14);
	force_instant_terrain_redraw();
	reset_dialog();
	add_dialog_str(0,"You were never called in to deal with bandits in any way.  You were called in to deal with spiders.  Hundreds of creepy-crawly spiders, with their dripping fangs, twitching legs, and...",0);
	add_dialog_str(1,"Maybe someday soon, more soldiers or mercenaries will be sent to clear this place out when they realize how horribly outclassed they are.  For now, however, it's mealtime.",0);
	add_dialog_str(2,"This strange brew didn't give you courage-- it gave you delusion.",0);
	add_dialog_choice(0,". . .");
	bmessage = run_dialog(1);
	block_entry(1);

	end_scenario(1);

break;

